package com.jinzhi.jzapi.common.controller;

import com.jinzhi.jzapi.common.pojo.NewTrainingCertificatesUtilsVo;
import com.jinzhi.jzapi.utils.CertificatesUtil;
import com.jinzhi.jzweb.domain.NewTrainingCertificatesDO;
import com.jinzhi.jzweb.service.NewTrainingCertificatesService;
import com.jinzhi.jzweb.utils.ValuesUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author mengzhichao
 * @create 2023-11-22-11:18
 */
@Component
public class NewCertificatesApittController {

    @Autowired
    private NewTrainingCertificatesService newTrainingCertificatesService;

    @Async
    public void doTask11(List<NewTrainingCertificatesUtilsVo> newTrainingCertificatesUtilsVos, List<NewTrainingCertificatesDO> newTrainingCertificatesDOS){
        // 实现run方法
        for (int i = 0; i < newTrainingCertificatesUtilsVos.size(); i++) {
            //证书图片
            String cerImgUrl = null;
            if (newTrainingCertificatesUtilsVos.get(i).getType() .equals("高级母婴护理师")) {
                try {
                    //参数说明：
                    cerImgUrl = CertificatesUtil.certificatesImge(newTrainingCertificatesUtilsVos.get(i).getName(),
                            newTrainingCertificatesUtilsVos.get(i).getType(),newTrainingCertificatesUtilsVos.get(i).getNumber(),newTrainingCertificatesUtilsVos.get(i).getWebAddress(),
                            newTrainingCertificatesUtilsVos.get(i).getStuImg(),newTrainingCertificatesUtilsVos.get(i).getQRImg(),newTrainingCertificatesUtilsVos.get(i).getBackgroundPath(),
                            newTrainingCertificatesUtilsVos.get(i).getYear(),newTrainingCertificatesUtilsVos.get(i).getMath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else   if (newTrainingCertificatesUtilsVos.get(i).getType() .equals("保育师师资证书")){
                try {
                    //参数说明：
                    cerImgUrl = CertificatesUtil.certificatesImge1(newTrainingCertificatesUtilsVos.get(i).getName(),
                            newTrainingCertificatesUtilsVos.get(i).getType(),newTrainingCertificatesUtilsVos.get(i).getNumber(),newTrainingCertificatesUtilsVos.get(i).getWebAddress(),
                            newTrainingCertificatesUtilsVos.get(i).getStuImg(),newTrainingCertificatesUtilsVos.get(i).getQRImg(),newTrainingCertificatesUtilsVos.get(i).getBackgroundPath(),
                            newTrainingCertificatesUtilsVos.get(i).getYear(),newTrainingCertificatesUtilsVos.get(i).getMath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            else   if (newTrainingCertificatesUtilsVos.get(i).getType() .equals("整理收纳师")){
                try {
                    //参数说明：
                    cerImgUrl = CertificatesUtil.certificatesImge2(newTrainingCertificatesUtilsVos.get(i).getName(),
                            newTrainingCertificatesUtilsVos.get(i).getType(),newTrainingCertificatesUtilsVos.get(i).getNumber(),newTrainingCertificatesUtilsVos.get(i).getWebAddress(),
                            newTrainingCertificatesUtilsVos.get(i).getStuImg(),newTrainingCertificatesUtilsVos.get(i).getQRImg(),newTrainingCertificatesUtilsVos.get(i).getBackgroundPath(),
                            newTrainingCertificatesUtilsVos.get(i).getYear(),newTrainingCertificatesUtilsVos.get(i).getMath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            else   if (newTrainingCertificatesUtilsVos.get(i).getType() .equals("婴幼儿辅食师")){
                try {
                    //参数说明：
                    cerImgUrl = CertificatesUtil.certificatesImge3(newTrainingCertificatesUtilsVos.get(i).getName(),
                            newTrainingCertificatesUtilsVos.get(i).getType(),newTrainingCertificatesUtilsVos.get(i).getNumber(),newTrainingCertificatesUtilsVos.get(i).getWebAddress(),
                            newTrainingCertificatesUtilsVos.get(i).getStuImg(),newTrainingCertificatesUtilsVos.get(i).getQRImg(),newTrainingCertificatesUtilsVos.get(i).getBackgroundPath(),
                            newTrainingCertificatesUtilsVos.get(i).getYear(),newTrainingCertificatesUtilsVos.get(i).getMath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            else   if (newTrainingCertificatesUtilsVos.get(i).getType() .equals("早期教育指导师")){
                try {
                    //参数说明：
                    cerImgUrl = CertificatesUtil.certificatesImge4(newTrainingCertificatesUtilsVos.get(i).getName(),
                            newTrainingCertificatesUtilsVos.get(i).getType(),newTrainingCertificatesUtilsVos.get(i).getNumber(),newTrainingCertificatesUtilsVos.get(i).getWebAddress(),
                            newTrainingCertificatesUtilsVos.get(i).getStuImg(),newTrainingCertificatesUtilsVos.get(i).getQRImg(),newTrainingCertificatesUtilsVos.get(i).getBackgroundPath(),
                            newTrainingCertificatesUtilsVos.get(i).getYear(),newTrainingCertificatesUtilsVos.get(i).getMath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            else   if (newTrainingCertificatesUtilsVos.get(i).getType() .equals("家政保洁师")){
                try {
                    //参数说明：
                    cerImgUrl = CertificatesUtil.certificatesImge5(newTrainingCertificatesUtilsVos.get(i).getName(),
                            newTrainingCertificatesUtilsVos.get(i).getType(),newTrainingCertificatesUtilsVos.get(i).getNumber(),newTrainingCertificatesUtilsVos.get(i).getWebAddress(),
                            newTrainingCertificatesUtilsVos.get(i).getStuImg(),newTrainingCertificatesUtilsVos.get(i).getQRImg(),newTrainingCertificatesUtilsVos.get(i).getBackgroundPath(),
                            newTrainingCertificatesUtilsVos.get(i).getYear(),newTrainingCertificatesUtilsVos.get(i).getMath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            else   if (newTrainingCertificatesUtilsVos.get(i).getType() .equals("岗位能力培训合格证书")){
                try {
                    //参数说明：
                    cerImgUrl = CertificatesUtil.certificatesImge6(newTrainingCertificatesUtilsVos.get(i).getName(),newTrainingCertificatesUtilsVos.get(i).getNumber(),newTrainingCertificatesUtilsVos.get(i).getBackgroundPath(),newTrainingCertificatesUtilsVos.get(i).getYear(),newTrainingCertificatesUtilsVos.get(i).getMath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }


            //转换一下图片路径，将反斜杠替换掉
//            String url = cerImgUrl.replace(ValuesUtil.localUrl, ValuesUtil.returnUrl);
            String url = cerImgUrl.replace(ValuesUtil.localUrl, ValuesUtil.returnUrl1);
            String imgUrl1 = url.replace("\\", "/");
            newTrainingCertificatesDOS.get(i).setImgUrl(imgUrl1);//证书图片
        }
        newTrainingCertificatesService.updateBatchById(newTrainingCertificatesDOS,newTrainingCertificatesDOS.size());
    }

}
